package com.zhiyou100.controller.house;

import com.zhiyou100.dao.Impl.HouseDaoImpl;
import com.zhiyou100.emtity.House;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

/**
 * @description:
 * @author: 马跃
 * @create: 2021-01-22 15:17
 **/
@WebServlet("/houseAdd")
public class HouseAddServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String sf = request.getParameter("sf");
        String cs = request.getParameter("cs");
        String qy = request.getParameter("qy");
        House house = new House();
        house.setH_area(sf+cs+qy);
        try {
            BeanUtils.populate(house,request.getParameterMap());
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        new HouseDaoImpl().add(house);
        request.getRequestDispatcher("/houseQueryAll").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
